<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
		<link href="./favicon.ico" rel="shortcut icon" type="image/x-icon" />
		<title>Diff Patcher Stats</title>
		<script type="text/javascript" src="http://www.google.com/jsapi"></script>
		<script type="text/javascript">
			google.load('visualization', '1', {packages: ['corechart']});
		</script>
		<script type="text/javascript">
			function drawVisualization() {
				// Create and populate the data table.
				var data_clients = new google.visualization.DataTable();
				data_clients.addColumn('string', 'client');
				data_clients.addColumn('number', 'count');
<?php
$mysqli = new mysqli('MYSQL_HOST', 'MYSQL_USER', 'MYSQL_PASSWORD', 'MYSQL_DATABASE');
$result = $mysqli->query("SELECT client, COUNT(id) AS 'count' FROM diff_patcher GROUP BY client ORDER BY COUNT(id) DESC LIMIT 10");

echo sprintf("				data_clients.addRows(%d);\n", $result->num_rows);
$i = 0;
while ($obj = $result->fetch_object()) {
	echo sprintf("				data_clients.setValue(%d, 0, '%s');\n" . 
	             "				data_clients.setValue(%d, 1, %d);\n",
				 $i, $obj->client, $i, $obj->count);
	$i++;
}
$result->close();
?>
			
				// Create and populate the data table.
				var data_fonts = new google.visualization.DataTable();
				data_fonts.addColumn('string', 'client');
				data_fonts.addColumn('number', 'count');
<?php
$result = $mysqli->query("SELECT font, COUNT(id) AS 'count' FROM diff_patcher WHERE font!='' GROUP BY font ORDER BY COUNT(id) DESC LIMIT 7");

echo sprintf("				data_fonts.addRows(%d);\n", $result->num_rows);
$i = 0;
while ($obj = $result->fetch_object()) {
	echo sprintf("				data_fonts.setValue(%d, 0, '%s');\n" . 
	             "				data_fonts.setValue(%d, 1, %d);\n",
				 $i, $obj->font, $i, $obj->count);
	$i++;
}
$result->close();
$mysqli->close();
?>
			
				// Create and draw the visualization.
				new google.visualization.PieChart(document.getElementById('chart_clients')).
						draw(data_clients, {title:"Top 10 Clients Downloaded"});
				// Create and draw the visualization.
				new google.visualization.PieChart(document.getElementById('chart_fonts')).
						draw(data_fonts, {title:"Top Fonts Used"});
			}
			

			google.setOnLoadCallback(drawVisualization);
		</script>

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-16687257-8']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>

	</head>
	<body style="font-family: Arial;border: 0 none;">
		<div id="chart_clients" style="width: 725px; height: 400px;"></div>
		<div id="chart_fonts"   style="width: 725px; height: 400px;"></div>
	</body>
</html>
